#include <stdio.h>
#include <stdlib.h>
void cleanLand(char** grid, int gridSize, int ColSize,int row,int column)
{
    if(grid[row][column] == '1')
    {
        //不等于1则清零
        grid[row][column] = '0';
    }
    else
    {
        //不等于1则返回
        return ;
    }

    int newRow;
    int newColumn;
    //上
    if(row != 0)    //还能上
    {
        newRow = row - 1;
        cleanLand(grid,gridSize,ColSize,newRow,column);
    }

    if(row != gridSize - 1)    //还能下
    {
        newRow = row + 1;
        cleanLand(grid,gridSize,ColSize,newRow,column);
    }


    if(column != 0)        //还能左
    {
        newColumn = column - 1;
        cleanLand(grid,gridSize,ColSize,row,newColumn);
    }

    if(column != ColSize-1)  //还能右
    {
        newColumn = column + 1;
        cleanLand(grid,gridSize,ColSize,row,newColumn);
    }
    //到最后
}

int numIslands(char** grid, int gridSize, int* gridColSize)
{
    int row,column;
    int ReturnLand = 0;
    //传入的是字符型数组
    for(row = 0; row < gridSize ; row++)                        //行
    {
        for(column = 0; column < gridColSize[row] ;column++ )    //列
        {
            if(grid[row][column] == '1')
            {
                //出现的岛屿
                cleanLand(grid, gridSize,gridColSize[row],row,column);
                ReturnLand++;
            }
        }
    }
    return ReturnLand;
}

int main()
{
//    char test[][5] = {"11110","11010","11000","00000"};
    char test[][5] = {"11000","11000","00100","00011"};
    int gridSize = 4;
    int gridColSize[5] = {5,5,5,5,5};
    char *p[4];
    for (int i = 0; i < 4; ++i) {
        p[i]= test[i];
    }
    int ret = numIslands(p, gridSize, gridColSize);
    printf("%d", ret);
}